//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
    components: {//动态扩充组件或组件路径   
        //表单header、content、footer对应位置扩充的组件
        gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
        gridBody: '',
        gridFooter: '',
        //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
        modelHeader: '',
        modelBody: '',
        modelFooter: ''
    },
    buttons: { view: [], box: [], detail: [] },//扩展的按钮
    methods: {//事件扩展
        getFormOption (field) {
            let option;
            this.editFormOptions.forEach(x => {
                x.forEach(item => {
                    if (item.field == field) {
                        option = item;
                    }
                })
            })
            return option;
        },
        onInit () {
            let unitId = this.getFormOption('unitId')
            this.http.get('/api/CampHouseUnit/GetCampUnit').then(res => {
              unitId.data = []
              unitId.data = res.data.list.map(i => {
                return {
                  key: i.id,
                  value: i.name
                }
              })
            })
            this.editFormFields.dayNum = 0
            let parentId = this.getFormOption("parentId")
            let typeId = this.getFormOption("typeId")
            parentId.onChange = (v, o) => {
                let parma = {
                    unitId: this.editFormFields.unitId,
                    type: v,
                }
                this.http.get('/api/CampHouseType/GetHouseType', parma).then(res => {
                    typeId.data = res.data.map(i => {
                        return {
                            key: i.id,
                            value: i.name
                        }
                    })
                })
            }
            
        },
        rowClick ({ row, column, event }) {
            this.$refs.table.$refs.table.toggleRowSelection(row);
            return true;
        },
        addBefore (formData) {
            this.setNum(formData)
            return true;
        },
        updateBefore (formData) {
            this.setNum(formData)
            return true;
        },
        setNum (formData) {
            if (this.editFormFields.openDate) {
                formData.mainData.startTime = this.editFormFields.openDate[0]
                formData.mainData.endTime = this.editFormFields.openDate[1]
            }
            let typeId = this.getFormOption("typeId")
            formData.mainData.typeName = typeId.data.filter(i => {
                if (i.key == this.editFormFields.typeId) {
                    return i
                }
            })[0].value
        },
        modelOpenBefore (row) {
            let typeId = this.getFormOption("typeId")
            let parma = {
                unitId: row.unitId,
                type: row.parentId,
            }
            this.http.get('/api/CampHouseType/GetHouseType', parma).then(res => {
                typeId.data = res.data.map(i => {
                    return {
                        key: i.id,
                        value: i.name
                    }
                })
                this.editFormFields.typeId = row.typeId
            })
        },
        modelOpenAfter (row) {
            if (this.currentAction == 'Add') {
                this.editFormFields.dayNum = 0
            } else {

                this.editFormFields.openDate = [row.startTime, row.endTime]
            }
        }
    }
};
export default extension;